package com.ccq.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ccq.entity.BlogTitle;
import com.ccq.entity.Comment;
import com.ccq.entity.User;
import com.ccq.repository.BlogTitleRepository;
import com.ccq.service.BlogService;

@Service
public class BlogServiceImpl implements BlogService {
	
	
	@Autowired
	private BlogTitleRepository blogTitleRepository;

	@Override
	public List<BlogTitle> blogPage() {
		
		return blogTitleRepository.blogPage();
	}

	@Override
	public void add(BlogTitle blog) {
		User u = new User();
		u.setId(1);
		blog.setAuthor(u);
		blog.setCreateTime(new Date());
		blogTitleRepository.add(blog);
		
	}

	@Override
	public Comment addComment(Integer blogId, String comment) {
		BlogTitle blogTitle = new BlogTitle();
		blogTitle.setId(blogId);
		Comment c = new Comment();
		c.setBlogTitle(blogTitle);
		c.setComment(comment);
		c.setCreateTime(new Date());
		
		return blogTitleRepository.addComment(c);
	}

}
